<?php
namespace App\Services;


use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Text;

class WeWorkService {

   public $app;

   public function __construct() {
       $corp_id = config('services.wework.corpId');

       $secret = config('services.wework.secret');

       $agent_id = config('services.wework.agentId');

       $config = [
           'corp_id'       => $corp_id,
           'secret'        => $secret,
           'agent_id'      => $agent_id,
           'response_type' => 'array',
//           'log'    => [
//               'level' => 'debug',
//               'file'  => __DIR__ . '/wechat.log',
//           ]
       ];

       $this->app = Factory::work($config);
   }

   public function getUserInfo($mobile)
   {
        return $this->app->user->mobileToUserId($mobile);
   }

   public function setMessage($userid, $content)
   {
       $messenger = $this->app->messenger;

       $message = new Text($content);

       $messenger->message($message)->toUser($userid)->send();
   }
}
